
/**
 * 
 * @param {*} position 太阳中心
 * @param {*} r   太阳半径
 * @param {*} num  辐射条数
 */

function getSunPath(position,r,num){
  var num=num||4
  var angle=2*Math.PI/(num) //线段旋转角

  var len=20 //线段长度
  var distance=Math.random()*5+5+r||25 //与中心间隔

  var path=[]
  for(let i=0;i<num;i++){

    var obj={
      x:distance*(Math.cos(angle*i).toFixed(2))+position.x,
      y:position.y-distance*(Math.sin(angle*i).toFixed(2))
    }
    path.push(obj)
  }
  return path
}



import {sentenceA} from "../../../../static/data/loginData"
var count=0
var add=true
function drawCloud(ctx,cvs){
  ctx.save()
  ctx.strokeStyle = '#fff';
  ctx.beginPath();
  ctx.fillStyle = '#fff';
  ctx.font="18px Arial";
  ctx.shadowOffsetX = 5;
  ctx.shadowOffsetY = 5;
  ctx.shadowBlur = 5;
  ctx.shadowColor = '#000';
  setInterval(()=>{
    textRandom(ctx,cvs)
  },2000)

  ctx.closePath();
  ctx.fill();
  ctx.stroke(); 
}

function textRandom(ctx,cvs){
  ctx.clearRect(120,30, cvs.width, cvs.height);
  var text=sentenceA[count]
  ctx.fillText(text,120,60,150);
  if(add){
    count++
  }else{
    count--
  }
  if(count==0){
    add=true
  }else if(count==sentenceA.length-1){
    add=false
  }
}

function drawSun(id){
  var cvs = document.getElementById(id);
  var ctx = cvs.getContext("2d");
  ctx.beginPath();
  ctx.arc(80, 0, 20, 0, Math.PI * 2, true);
  ctx.closePath();
  ctx.fillStyle = 'gold';
  ctx.fill();
  var path=getSunPath({x:80,y:0},30,15)

  ctx.beginPath();
  for(let i=0;i<path.length;i++){
    ctx.lineTo(path[i].x,path[i].y-10);
    ctx.lineTo(path[i].x,path[i].y+10);
  }
  ctx.closePath();
  ctx.strokeStyle = '#fff';
  ctx.stroke();
  drawCloud(ctx,cvs)
}

export {drawSun}